package com.lucher.mes.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.support.RequestContext;

public class BaseController {
	protected String message = "";
	protected boolean result = false;
	protected boolean errorFlags = false;
	
	public HttpServletRequest getRequest(){
		return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
	}
	public HttpSession getSession(){
		getRequest().getSession().setMaxInactiveInterval(36000);//单位秒，设置Session连接时间
		return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest().getSession();
	}
	
	public String getMessage(String name){
		RequestContext requestContext = new RequestContext(getRequest());
		return requestContext.getMessage(name);
	}
	
	/**
     * 数据绑定，
     * springMVC框架提交参数list时，springmvc默认只能接收到255个数据,当你前台传的数据长度大于255位的时候就会报错 
     * @param binder
     *  WebDataBinder
     */
    @InitBinder
    protected void initBinder(WebDataBinder binder) {
        binder.setAutoGrowCollectionLimit(20480);  
    }
}
